package com.jackrain.nea.ext.oss;

import lombok.Getter;

import java.text.MessageFormat;

/**
 * Oss连接异常
 *
 * @author blqw
 * @date 2017-12
 */
public class OssConnectException extends RuntimeException {

    /**
     * 访问密钥id
     */
    @Getter
    private String accessKeyId;
    /**
     * 访问密钥密码
     */
    @Getter
    private String accessKeySecret;
    /**
     * 终结点
     */
    @Getter
    private String endpoint;
    /**
     * 存储空间
     */
    @Getter
    private String bucket;

    /**
     * 初始化
     *
     * @param accessKeyId     访问密钥id
     * @param accessKeySecret 访问密钥密码
     * @param endpoint        终结点
     * @param bucket          存储空间
     * @param ex              内部异常
     */
    public OssConnectException(String accessKeyId, String accessKeySecret, String endpoint, String bucket, Throwable ex) {
        super(MessageFormat.format("使用参数 accessKeyId={0},accessKeySecret=***{1},endpoint={2} 初始化OSS失败:{3}",
                accessKeyId,
                accessKeySecret.length() > 4 ? accessKeySecret.substring(0, 4) : accessKeySecret,
                endpoint,
                ex == null ? "<null>" : ex.getMessage() == null ? ex.toString() : ex.getMessage()
        ), ex);

        this.accessKeyId = accessKeyId;
        this.accessKeySecret = accessKeySecret;
        this.endpoint = endpoint;
        this.bucket = bucket;
    }
}
